#include "XRCORE.h"

// ??????????????????
unsigned char BytesAdd(unsigned char *ABytes, unsigned short APosition, unsigned short ACount)
{
    // var
    unsigned char result = 0;
    unsigned short oI;

    for (oI = APosition; oI < APosition + ACount; oI++) {
        result = result + ABytes[oI];
    }

    return result;
}

// ?????????????????
unsigned char BytesXor(unsigned char *ABytes, unsigned short APosition, unsigned short ACount)
{
    // var
    unsigned char result = 0;
    unsigned short oI;

    for (oI = APosition; oI < APosition + ACount; oI++) {
        result = result ^ ABytes[oI];
    }

    return result;
}


// ????????????????????
unsigned char BytesAddReverse(unsigned char *ABytes, unsigned short APosition, unsigned short ACount)
{
    return BytesAdd(ABytes, APosition, ACount) ^ 0xFF;
}

//????????BCD?
unsigned char ByteToBcd ( unsigned char AValue )
{
    return (AValue / 10) * 0x10 + (AValue % 10);
}
//BCD?????????
unsigned char BcdToByte ( unsigned char AValue )
{
    return (AValue / 0x10) * 10 + (AValue % 0x10);
}

